<section id="main-content">
	<section class="wrapper">
		<!--state overview start-->
		<div class="row first">
			<div class="col-lg-12">
				<!--<div class="alert alert-warning fade in">-->
				<!--<button data-dismiss="alert" class="close close-sm" type="button">-->
				<!--<i class="icon-remove"></i>-->
				<!--</button>-->
				<!--<strong>备注说明：</strong> 本页面默认提供三个维度的项目进展，分别是本部门归属的项目、本部门人员参与的外部项目、本部门产品相关的项目。-->
				<!--</div>-->

				<section class="panel" ng-show="isShow">
					<div class="panel-body" style="padding-bottom: 0;">
						<div class="row">
							<div class="col-lg-3">
								<div class="input-group m-bot15">
									<span class="input-group-addon">流程类型</span>
									<input type="text" id="prcType" class="form-control" placeholder="例如：用章">
								</div>
							</div>
							<div class="col-lg-2">
								<div class="input-group m-bot15">
									<span class="input-group-addon" style="position: relative;z-index: 2;">所属公司</span>
									<select class="form-control"
										style="position: relative;margin-left:-4px;text-indent:2px;"
										id="company" ng-model="company" onchange="getDepts()">
										<option value="" selected>全部公司</option>
										<option ng-repeat="x in comp" value="{{x.companyId}}">{{x.company}}</option>
									</select>
								</div>
							</div>
							<div class="col-lg-3">
								<div class="input-group m-bot15">
									<span class="input-group-addon" style="position: relative;z-index: 2;">部门/岗位</span>
									<select class="form-control"
										style="position: relative;margin-left:-4px;text-indent:4px;"
										id="deptCode" onchange="getChildDept(this.value)">
										<option value="" selected>全部部门</option>
										<option ng-repeat="x in dept" value="{{x.departmentCode}}">{{x.departmentName}}</option>
									</select>
								</div>
							</div>
							<div class="col-lg-3">
								<div class="input-group m-bot15">
									<span class="input-group-addon" style="position: relative;z-index: 2;">下级部门</span>
									<select class="form-control"
										style="position: relative;margin-left:-4px;text-indent:4px;"
										id="childCode">
										<option value="" selected>全部部门</option>
										<option ng-repeat="x in childdept" value="{{x.departmentCode}}">{{x.departmentName}}
										</option>
									</select>
								</div>
							</div>
							<div class="col-lg-1">
								<button class="btn btn-info searchs" style="margin-bottom: 15px;">搜索</button>
							</div>
						</div>

					</div>
				</section>




				<!-- <div class="view-header" ng-show="isShow">
					<div class="view-search" style="margin:0;">
						<label class="pull-left" style="margin:0;">审批类型：</label>
						<input type="text" class="form-control" value="" id="prcType" />
						<label class="pull-left" style="margin:0;">所属公司：</label>
						<select class="form-control pull-left" id="company" ng-model="company" onchange="getDepts()">
							<option value="" selected>全部公司</option>
							<option ng-repeat="x in comp" value="{{x.companyId}}">{{x.company}}</option>
						</select>
						<select class="form-control pull-left" style="width: 80px;" id="isBm" onchange="getDepts()">
							<option value="" selected>全部</option>
							<option value="GW">岗位</option>
							<option value="BM">部门</option>
						</select>

						<label class="pull-left" style="margin:0;">部门/岗位：</label>
						<select class="form-control pull-left" id="deptCode" onchange="getChildDept(this.value)">
							<option value="" selected>全部部门</option>
							<option ng-repeat="x in dept" value="{{x.departmentCode}}">{{x.departmentName}}</option>
						</select>

						<label class="pull-left" style="margin:0;">子部门：</label>
						<select class="form-control pull-left" id="childCode">
							<option value="" selected>全部部门</option>
							<option ng-repeat="x in childdept" value="{{x.departmentCode}}">{{x.departmentName}}
							</option>
						</select>

						<a href="javascript:void(0);" class="btn btn-info pull-left searchs">搜索</a>
					</div>
				</div> -->
				<section class="panel">
					<header class="panel-heading">
						部门内审批关系
					</header>
					<div class="panel-body">
						<div id="spContainer" class="dlshouwen-grid-container"></div>
						<div id="spToolBarContainer" class="dlshouwen-grid-toolbar-container"></div>
					</div>
				</section>

				<section class="panel">
					<header class="panel-heading">
						我的审批权限
					</header>
					<div class="panel-body">
						<div id="myContainer" class="dlshouwen-grid-container"></div>
						<div id="myToolBarContainer" class="dlshouwen-grid-toolbar-container"></div>
					</div>
				</section>
			</div>
		</div>
		<!--state overview end-->
	</section>
</section>
<!-- 当前页面js文件引入 -->
<script type="text/javascript">
	function findSpxx($scope, CertusFormAjax) {
		var deptIds = "";
		var compIds = "";
		this.getDepts = function () {
			var company = $("#company").val();
			var isBm = $("#isBm").val();
			if (company != "") {
				findCompDepts(company, deptIds, isBm);
			} else {
				findCompDepts(compIds, deptIds, isBm);
			}
		};

		this.findCompDepts = function (company, depts, isBm) {
			CertusFormAjax.ajax("findCompDepts", { "compCodes": company, "deptIds": depts, "isBm": isBm }, function (response) {
				var data = response.data;
				$scope.dept = data;
			});
		};

		this.getChildDept = function (pardepts) {
			CertusFormAjax.ajax("childDeptList", { "deptCode": deptIds, "pdeptId": pardepts }, function (response) {
				$scope.childdept = response.data;
			});
		};

		this.findAllDepts = function (dept) {
			CertusFormAjax.ajax("findQDepts", { "deptIds": dept }, function (response) {
				var data = response.data;
				$scope.dept = data;
			});
		};
		CertusFormAjax.ajax("isCrcd", {
			"code": "SPXX"
		}, function (response) {
			var data = JSON.parse(response.data);
			deptIds = data.deptCode;
			compIds = data.comanyCode;
			if (data.comanyCode != "") {
				CertusFormAjax.ajax("companyListByCode", { "code": data.comanyCode }, function (response) {
					$scope.comp = JSON.parse(response.data);
				});
				findCompDepts(data.comanyCode, deptIds, "");
			} else {
				$("#company").attr("disabled", "disabled");
				findAllDepts(data.deptCode);
			}

			if (data.isTrue) {
				$scope.isShow = true;
			} else {
				$scope.isShow = false;
				search("", deptIds, "", compIds, false);
			}

			// if (data.isTrue == true) {
			//     search("", deptIds,compIds);
			// } else {
			//     CertusFormAjax.ajax("getDeptCode", {}, function (response) {
			//         var data1 = response.data;
			//         $scope.deptCode = data1;
			//         $("#deptCode").attr("disabled", "disabled");
			//         $("#deptFlag").html("归属");
			//         //默认查询
			//         search("", deptIds,compIds);
			//     });
			// }
		});
		this.search = function (prcType, deptCode, childCode, company, flag) {
			var msgColumns4 = [{
				id: 'company',
				title: '所属公司',
				type: 'string',
				columnClass: 'text-center'
			}, {
				id: 'department_name',
				title: '归属部门/岗位',
				type: 'string',
				// width: 150,
				columnClass: 'text-center'
			}, {
				id: 'is_true_department',
				title: '类型',
				type: 'string',
				columnClass: 'text-center',
				resolution: function (value) {
					var content = '';
					if (value == 1) {
						content += '部门';
					} else if (value == 2) {
						content += '岗位';
					} else {
						content += '子部门';
					}
					return content;
				}
			}, {
				id: 'user_name',
				title: '审批人',
				type: 'string',
				columnClass: 'text-center'
			}, {
				id: 'approve_level',
				title: '审批级别',
				type: 'string',
				columnClass: 'text-center'
			}, {
				id: 'min_value',
				title: '审批额度',
				type: 'string',
				columnClass: 'text-center',
				resolution: function (value) {
					var content = '';
					if (value == "0") {
						content += '';
					} else {
						content += value;
					}
					return content;
				}
			}, {
				id: 'process_type',
				title: '类型',
				type: 'string',
				columnClass: 'text-center'
			}, {
				id: 'comments',
				title: '说明',
				type: 'string',
				columnClass: 'text-center'
			}];
			$("#spContainer").empty();
			$("#spToolBarContainer").empty();
			CertusFormAjax.ajax('findProcessSps', {
				"processType": prcType,
				"deptCode": deptCode, "childCode": childCode, "company": company, "flag": flag
			}, function (response) {
				var makingOption = {
					lang: 'zh-cn',
					ajaxLoad: false,
					extraWidth: 20,
					// loadURL:'url',
					exportFileName: '审批信息列表',
					datas: response.data,
					columns: msgColumns4,
					gridContainer: 'spContainer',
					toolbarContainer: 'spToolBarContainer',
					tools: '',
					pageSize: 20,
					pageSizeLimit: [20, 30, 40]
				};
				var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
				makingGrid.load();
			});
		}
		$(".searchs").on('click', function () {
			var prcType = $("#prcType").val();
			var deptCode = $("#deptCode").val();
			var company = $("#company").val();
			var childCode = $("#childCode").val();
			if (company == "") {
				layer.msg("请选择公司");
				return;
			}
			search(prcType, deptCode, childCode, company, $scope.isShow);
		});

		//我的审批关系
		var msgColumns5 = [{
			id: 'company',
			title: '所属公司',
			type: 'string',
			columnClass: 'text-center'
		}, {
			id: 'department_name',
			title: '归属部门/岗位',
			type: 'string',
			// width: 150,
			columnClass: 'text-center'
		}, {
			id: 'is_true_department',
			title: '类型',
			type: 'string',
			columnClass: 'text-center',
			resolution: function (value) {
				var content = '';
				if (value == 1) {
					content += '部门';
				} else if (value == 2) {
					content += '岗位';
				} else {
					content += '子部门';
				}
				return content;
			}
		}, {
			id: 'user_name',
			title: '审批人',
			type: 'string',
			columnClass: 'text-center'
		}, {
			id: 'approve_level',
			title: '审批级别',
			type: 'string',
			columnClass: 'text-center'
		}, {
			id: 'min_value',
			title: '审批额度',
			type: 'string',
			columnClass: 'text-center',
			resolution: function (value) {
				var content = '';
				if (value == "0") {
					content += '';
				} else {
					content += value;
				}
				return content;
			}
		}, {
			id: 'process_type',
			title: '类型',
			type: 'string',
			columnClass: 'text-center'
		}, {
			id: 'comments',
			title: '说明',
			type: 'string',
			columnClass: 'text-center'
		}];
		CertusFormAjax.ajax('findProcessSps', {
			"processType": "",
			"deptCode": "", "childCode": "", "company": "", "flag": false, "flag1": "0"
		}, function (response) {
			var makingOption = {
				lang: 'zh-cn',
				ajaxLoad: false,
				extraWidth: 20,
				// loadURL:'url',
				exportFileName: '我的审批权限列表',
				datas: response.data,
				columns: msgColumns5,
				gridContainer: 'myContainer',
				toolbarContainer: 'myToolBarContainer',
				tools: '',
				pageSize: 20,
				pageSizeLimit: [20, 30, 40]
			};
			var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
			makingGrid.load();
		});
	}
</script>